﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace LiteFramework
{
    /// <summary>
    /// 指示一个属性不可见。
    /// <para>　　一般用于枚举，指示枚举项对于用户界面不可见</para>
    /// </summary>
    [Serializable]
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
    [ComVisible(true)]
    public sealed class InvisibleAttribute : System.Attribute, IComparable<InvisibleAttribute>, IComparer<InvisibleAttribute>
    {
        private bool _invisible = true;

        /// <summary>
        /// 初始化新实例
        /// </summary>
        public InvisibleAttribute()
            : base()
        {
        }

        /// <summary>
        /// 初始化新实例
        /// </summary>
        /// <param name="invisible">是否不可见 (默认: true)</param>
        public InvisibleAttribute(bool invisible)
            : base()
        {
            this._invisible = invisible;
        }

        /// <summary>
        /// 提示属性是否不可见
        /// </summary>
        public bool Invisible
        {
            get { return this._invisible; }
            set { this._invisible = value; }
        }

        #region IComparable 成员

        public int CompareTo(object obj)
        {
            return CompareTo(obj as InvisibleAttribute);
        }

        #endregion

        #region IComparer<SortableAttribute> 成员

        public int Compare(InvisibleAttribute x, InvisibleAttribute y)
        {
            if (Object.ReferenceEquals(x, y))
                return 0;

            if (x == y)
                return 0;

            if (x == null)
                return -1;

            if (y == null)
                return 1;

            int result = x.Invisible.CompareTo(y.Invisible);

            //if (result == 0)
            //    result = x.xxx.CompareTo(y.xxx);

            return result;
        }

        #endregion

        #region IComparable<SortableAttribute> 成员

        int IComparable<InvisibleAttribute>.CompareTo(InvisibleAttribute other)
        {
            return Compare(this, other);
        }

        #endregion
    }
}
